package com.wei.duowan.bbs.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.wei.duowan.bbs.R;
import com.wei.duowan.bbs.model.ForumsBean;
import com.wei.duowan.bbs.presenter.BasePresenter;
import com.wei.duowan.bbs.ui.activity.FormumsActivity;
import com.wei.duowan.bbs.ui.adapter.BaseRecyclerViewAdapter;
import com.wei.duowan.bbs.ui.adapter.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * 作者：赵若位
 * 时间：2019/8/2 16:28
 * 联系方式：1070138445
 * 功能：
 */
public class ForumsChildFragment extends BaseLazyFragment
{
    private ForumsBean mData = null;

    @Bind(R.id.recyclerView)
    RecyclerView mRecyclerView;

    private BaseRecyclerViewAdapter mAdapter;


    public static ForumsChildFragment getFragment(@Nullable ForumsBean data)
    {
        if (data != null)
        {
            ForumsChildFragment fragment = new ForumsChildFragment();
            Bundle bundle = new Bundle();
            bundle.putParcelable(TAG,data);
            fragment.setArguments(bundle);
            return fragment;
        }
        return null;
    }


    @Override
    protected BasePresenter createPresenter()
    {
        return null;
    }

    @Override
    protected int getLayoutID()
    {
        return R.layout.fragment_forums_child;
    }

    @Override
    protected void initView()
    {
        mData = getArguments().getParcelable(TAG);

        GridLayoutManager manager = new GridLayoutManager(mActivity, 3);
        mRecyclerView.setLayoutManager(manager);

        //TODO 调整一下布局格式
        mAdapter = new BaseRecyclerViewAdapter<ForumsBean>(mActivity, R.layout.layout_forums)
        {
            @Override
            protected void convert(int position, @Nullable BaseViewHolder holder, @Nullable ForumsBean data)
            {
                holder.setCircleResource(R.id.img_game, data.getIcon())
                        .setText(R.id.tv_title, data.getName())
                        .itemView.setOnClickListener(view -> ForumsChildFragment.this.mActivity.openActivity(FormumsActivity.class));
                Log.e(TAG, "convert: "+data.getFid());
            }
        }.setIsEmpty(true);
        mAdapter.bindRecyclerView(mRecyclerView);
    }

    @Override
    public void initData()
    {
        List<ForumsBean> list = ForumsBean.getForumsBean(mData.getFid());
        mAdapter.setNewData(list);
    }
}
